<?php

namespace app\reception\validate;

use think\Validate;

class PageValidate extends Validate
{
    protected $rule = [
        'seat' => 'require|in:0,1,2,3',
        'freq' => 'require|in:0,1,2',
        'title' => 'require',
        'page' => 'number|egt:1',
        'limit' => 'number|gt:0',
        'is_vip' => 'number|in:0,1',
        'activity_id' => 'require|number|gt:0',
        'location_key' => 'require',
        'location_keys' => 'require',
        'limits' => 'require|checkLimits',
    ];

    protected $message = [

    ];

    protected $scene = [
        'getBanner' => ['seat'],
        'rechargeItems' => ['is_vip'],
        'getActivityRecharge' => ['activity_id'],
        'getBatchRecommendNovels' => ['location_keys', 'limits'],
    ];

    public function sceneGetRecommendNovels()
    {
        return $this->only(['location_key', 'page', 'limit'])
            ->append('limit', 'require');
    }

    protected function checkLimits($value, $rule, $data = [])
    {
        if (!preg_match('#^[1-9][0-9]*(,[1-9][0-9]*)*$#', $value)) {
            return '参数异常，limits格式异常';
        }
        return true;
    }
}